<template>
  <!--
      作者：luoyiming
      时间：2019-10-25
      描述：售后管理
  -->
  <div class="user">
    <!--搜索表单-->
   <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
		<el-form-item label="所属分组">
			<el-select v-model="formInline.group_id" clearable  placeholder="请选择">
			    <el-option
			      v-for="item in group"
			      :key="item.grade_id"
			      :label="item.name"
			      :value="item.grade_id">
			    </el-option>
			  </el-select>
		</el-form-item>
		<el-form-item label="用户ID"><el-input v-model="formInline.user_id" placeholder="请输入用户ID"></el-input></el-form-item>
        <el-form-item label="订单号"><el-input v-model="formInline.order_no" placeholder="请输入订单号"></el-input></el-form-item>
        <el-form-item label="参与时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker v-model="formInline.create_time" type="daterange" value-format="YYYY-MM-DD" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item><el-button type="primary" icon="Search" @click="onSubmit()">查询</el-button></el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-tabs v-model="activeName" @tab-change="handleClick"> 
          <el-tab-pane name="10">
            <template #label>
              <span>全部</span>
            </template>
          </el-tab-pane>
		 <!-- <el-tab-pane name="50">
		    <template #label>
		      <span> 待排队</span>
		    </template>
		  </el-tab-pane> -->
          <el-tab-pane name="20">
            <template #label>
              <span> 排队中</span>
            </template>
          </el-tab-pane> 
          <el-tab-pane name="30">
            <template #label>
             <span> 免单中</span>
            </template>
          </el-tab-pane>
          <el-tab-pane name="40">
            <template #label>
              <span>已完成</span>
            </template>
          </el-tab-pane>
        
        </el-tabs>
        <el-table :data="tableData" border style="width: 100%" v-loading="loading">
			<el-table-column prop="user_id" label="用户ID"></el-table-column>
			<el-table-column prop="nickName" label="用户昵称"></el-table-column>
			<el-table-column prop="mobile" label="用户号码"></el-table-column>
			<el-table-column prop="product_name" label="产品名称"></el-table-column>
			<el-table-column prop="percentage" label="免单进度">
				<template #default="scope">
					{{scope.row.percentage}}%/100%
				</template>
			</el-table-column>
			<el-table-column prop="membernum" label="当前排名"></el-table-column>
			<el-table-column prop="pay_price" label="订单金额"></el-table-column>
			<el-table-column prop="end_order_product_price" label="返利金额"></el-table-column>
			<el-table-column prop="order_no" label="订单编号"></el-table-column>
			<el-table-column prop="timestamp" label="创建时间"></el-table-column>
			<el-table-column prop="finishstamp" label="完成时间"></el-table-column>
			<el-table-column prop="groupname" label="所属分组"></el-table-column>
          <el-table-column fixed="right" label="操作" width="80">
            <template #default="scope">
              <p><el-button @click="Detail(scope.row.order_id)"  link type="primary" size="small">订单详情</el-button></p>
			   <p><el-button @click="deleteline(scope.row.id)" v-if="scope.row.status==0||scope.row.status==-1"  link type="primary" size="small">删除排队</el-button></p>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-sizes="[2, 10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
	import OrderApi from '@/api/order.js';
// import {lineup,deletelineup} from '@/api/order.js';
export default {
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        order_no: '',
        style_id: '',
        shop_id: '',
        create_time: '',
		user_id:'',
		group_id:'',
      },
      status: 10, 
      arr: [],
	  group:[],
      activeName: '10'
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      this.curPage = val;
      this.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*切换菜单*/
    handleClick(tabName) {
      this.curPage = 1;
      this.status = tabName;
      this.getTableList();
    },

    /*获取列表*/
    getTableList(params = '') {
      let self = this;
      let Params = this.formInline;
      Params.status = self.status;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      if (params != '') {
        Params.order_no = params.order_no;
        Params.create_time = params.create_time;
        Params.type = params.type;
      }
      self.loading = true;
      OrderApi.lineup(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list;
          self.totalDataNumber = data.data.total;
		  self.group = data.data.group;
        })
        .catch(error => {});
    },

    /*搜索查询*/
    onSubmit() {
      let self = this;
      let Params = this.formInline;
      self.getTableList(Params);
    },

    /*详情*/
    Detail(e) {
      let self = this;
      let order_id = e;
      this.$router.push({
        path: '/order/order/detail',
        query: {
          order_id: order_id
        }
      });
    },
	deleteline(id){
		let self = this;
		ElMessageBox.confirm('此操作将永久删除该记录, 是否继续?', '提示', {
		  confirmButtonText: '确定',
		  cancelButtonText: '取消',
		  type: 'warning'
		}).then(() => {
		  self.loading = true;
		  OrderApi.deletelineup({
		      id: id
		    }, true)
		    .then(data => {
		      self.loading = false;
		      if (data.code == 1) {
		        ElMessage({
		          message: data.msg,
		          type: 'success'
		        });
		        self.getTableList();
		      } else {
		        ElMessage.error('错了哦，这是一条错误消息');
		      }
		    })
		    .catch(error => {
		      self.loading = false;
		    });
		
		}).catch(() => {
		
		});
	},
  }
};
</script>
<style></style>
